package com.example.anni.zhuzhoujia.tianya12345;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextPaint;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.anni.zhuzhoujia.R;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangshengwen2016 on 2016/6/30.
 * 爆料详情
 */
public class BrokeDetailsA extends AppCompatActivity {
    private String passId;
    public String user;//个人信息
    public String avatar;//头像
    public String nickName;//昵称
    public String gender;//性别
    public String dateline;//爆料时间
    public String title;//标题
    public String content;//内容
    public String good;//赞
    public String bad;//踩
    public String commentNum;//评论数
    public String images;//图片
    public String id;//ID
    public String fact;//是否真实
    public String fromUrl;//来源网址
    public String newsType;//新闻类型
    public String source;//来源
    public String status;//处理状态
    public String area;//区域
    public String views;//浏览量
    public TextView tv_good;
    public TextView tv_bad;
    public List<Map<String, Object>> list;
    public StationaryGridview grid_item;//GridView
    private int width;
    private int height;
    private String[] tabs = {"加载图片", "不加载图片", "隐藏图片", "显示图片"};
    private List<Map<String, Object>> list_tab;

    //选项卡
    private void tabData() {
        list_tab = new ArrayList<>();
        for (int i = 0; i < tabs.length; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("tabs", tabs[i]);
            list_tab.add(map);
        }
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.broke_details);
        tabData();
        //获取屏幕高度和宽度
        WindowManager wm = this.getWindowManager();
        width = wm.getDefaultDisplay().getWidth();
        height = wm.getDefaultDisplay().getHeight();
        LinearLayout city_return = (LinearLayout) findViewById(R.id.city_return);//返回图片
        city_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //调用登录接口
        RequestParams params1 = new RequestParams("http://tr.zzapi.gson.cn/api/user/login");
//        params1.addBodyParameter("userName", "以前我是个爱仰望天空的人是个爱仰望天空的人，苍蓝的天空总是给我求生的勇气，而现在我喜欢深邃的夜空，包容一切的黑暗和隐忍");
        params1.addBodyParameter("userName", "酷酷猫");
        params1.addBodyParameter("password", "666666");
        x.http().post(params1, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String s) {

            }

            @Override
            public void onError(Throwable throwable, boolean b) {

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
        TextView title_toolbar = (TextView) findViewById(R.id.title_toolbar);
        tv_good = (TextView) findViewById(R.id.good);
        tv_bad = (TextView) findViewById(R.id.bad);
        title_toolbar.setText("爆料详情");
        //获取外面传过来的id
        Intent intent = getIntent();
        passId = intent.getStringExtra("id");
//        Toast.makeText(BrokeDetailsA.this, passId, Toast.LENGTH_LONG).show();
        detailsData();//爆料详情
        good(passId);//赞的方法
        bad(passId);//踩的方法
        publishComment(passId);//评论的方法
    }

    public void detailsData() {
        //获取爆料详情
        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/news/detail?id=" + passId);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String s) {
                JSONObject json = JSON.parseObject(s);
                String data = json.getString("data");
                JSONObject json2 = JSON.parseObject(data);
                String news = json2.getString("news");//新闻
                JSONObject json3 = JSON.parseObject(news);//解析新闻
                if (json2.getJSONArray("related") != null) {
                    JSONArray related = json2.getJSONArray("related");//相关爆料
                    int k = 0;
                    for (int i = 0; i < related.size(); i++) {
                        JSONObject objRelated = related.getJSONObject(i);
                        if (objRelated.getString("newsType").equals("FACT") & !objRelated.getString("id").equals(passId)) {
                            LinearLayout linexg = (LinearLayout) findViewById(R.id.linexg);//相关线
                            LinearLayout linear_related = (LinearLayout) findViewById(R.id.linear_related);
                            linexg.setVisibility(View.VISIBLE);
                            linear_related.setVisibility(View.VISIBLE);
                            final String relatedId = objRelated.getString("id");
                            String relatedtitle = objRelated.getString("title");
                            String relateddateline = objRelated.getString("dateline");
                            String relatedViews = objRelated.getString("views");
                            //相关爆料线
                            TextView xian = new TextView(BrokeDetailsA.this);
                            LinearLayout.LayoutParams xianIp = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT, 1);
                            xianIp.setMargins(20, 0, 20, 0);
                            xian.setLayoutParams(xianIp);
                            xian.setBackgroundColor(0xffaaaaaa);
                            if (k != 0) {
                                linear_related.addView(xian);
                            }
                            k++;
                            //相关爆料项
                            LinearLayout linearLayout1 = new LinearLayout(BrokeDetailsA.this);
                            LinearLayout.LayoutParams linearLayoutIp1 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            linearLayoutIp1.setMargins(10, 0, 10, 0);
                            linearLayout1.setLayoutParams(linearLayoutIp1);
                            linearLayout1.setOrientation(LinearLayout.VERTICAL);
                            linear_related.addView(linearLayout1);
                            //点击查看爆料
                            linearLayout1.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/news/detail?id=" + relatedId);
                                    x.http().get(params, new Callback.CommonCallback<String>() {

                                        @Override
                                        public void onSuccess(String s) {
                                            JSONObject json = JSON.parseObject(s);
                                            String success = json.getString("success");
                                            if (success.equals("true")) {
                                                Intent intent = new Intent(BrokeDetailsA.this, BrokeDetailsA.class);
                                                intent.putExtra("id", relatedId);
                                                startActivity(intent);
                                            } else {
                                                Toast.makeText(BrokeDetailsA.this, "该爆料尚未通过审核！", Toast.LENGTH_SHORT).show();
                                            }
                                        }

                                        @Override
                                        public void onError(Throwable throwable, boolean b) {

                                        }

                                        @Override
                                        public void onCancelled(CancelledException e) {

                                        }

                                        @Override
                                        public void onFinished() {

                                        }
                                    });
                                }
                            });
                            linearLayout1.setBackgroundResource(R.drawable.ysw_bt_5);
                            //相关爆料标题
                            TextView textView1 = new TextView(BrokeDetailsA.this);
                            TextPaint tp = textView1.getPaint();
//                            tp.setFakeBoldText(true);//设置粗体
//                            textView1.setTextColor(0xff000000);
                            textView1.setTextSize(16);
                            textView1.setSingleLine(true);
                            LinearLayout.LayoutParams textViewIp = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            textViewIp.setMargins(20, 10, 20, 0);
                            textView1.setText(relatedtitle);
                            textView1.setLayoutParams(textViewIp);
                            linearLayout1.addView(textView1);
                            //时间和浏览量
                            LinearLayout linearLayout2 = new LinearLayout(BrokeDetailsA.this);
                            LinearLayout.LayoutParams linearLayoutIp2 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT
                            );
                            linearLayout2.setLayoutParams(linearLayoutIp2);
                            linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
                            linearLayout1.addView(linearLayout2);
                            //相关爆料时间
                            TextView textView2 = new TextView(BrokeDetailsA.this);
                            LinearLayout.LayoutParams textViewIp2 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT);
                            textViewIp2.setMargins(30, 3, 50, 15);
                            textView2.setText(relateddateline);
                            textView2.setLayoutParams(textViewIp2);
                            textView2.setTextColor(0xffaaaaaa);
                            textView2.setTextSize(12);
                            linearLayout2.addView(textView2);
                            //相关爆料浏览量
                            TextView textView3 = new TextView(BrokeDetailsA.this);
                            LinearLayout.LayoutParams textViewIp3 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT);
                            textViewIp3.setMargins(0, 3, 0, 15);
                            textView3.setText("浏览 " + relatedViews);
                            textView3.setLayoutParams(textViewIp3);
                            textView3.setTextColor(0xffaaaaaa);
                            textView3.setTextSize(12);
                            linearLayout2.addView(textView3);
                        }
                    }
                }
                comment(passId);//评论区
                title = json3.getString("title");//标题
                content = json3.getString("content");//内容
                dateline = json3.getString("dateline");//爆料时间
                good = json3.getString("good");//赞
                id = json3.getString("id");//id
                bad = json3.getString("bad");//踩
                commentNum = json3.getString("commentNum");//评论数
                images = json3.getString("images");//所有图片
                        //读取数据
                        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(BrokeDetailsA.this);
                        String LoadImage = sp.getString("LoadImage", "");
                        if (LoadImage.equals("no1")) {
                            images = "";
                        }
                fact = json3.getString("fact");//是否真实
                fromUrl = json3.getString("fromUrl");//来源网址
                newsType = json3.getString("newsType");//新闻类型
                status = json3.getString("status");//处理状态
                area = json3.getString("area");//区域
                views = json3.getString("views");//浏览量
                user = json3.getString("user");
                JSONObject obj2 = JSON.parseObject(user);
                avatar = obj2.getString("avatar");//头像
                nickName = obj2.getString("nickName");//昵称
                gender = obj2.getString("gender");//性别

                if (images.length() == 0) {
                    LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                    linear_img.setVisibility(View.GONE);
                } else {
                    LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                    linear_img.setVisibility(View.VISIBLE);
                }
                TextView tv_title = (TextView) findViewById(R.id.title);
                tv_title.setText(title);//标题
                TextView tv_content = (TextView) findViewById(R.id.content);
                tv_content.setText(content);//内容
                TextView tv_newsType = (TextView) findViewById(R.id.newsType);
                if (newsType.equals("FACT")) {
                    tv_newsType.setText("爆料");//新闻类型
                }
                TextView tv_dateline = (TextView) findViewById(R.id.dateline);
                tv_dateline.setText(dateline);//时间
                TextView tv_views = (TextView) findViewById(R.id.views);
                tv_views.setText(views);//浏览量
                TextView tv_nickName = (TextView) findViewById(R.id.nickName);
                tv_nickName.setText("爆料者：" + nickName);//爆料者
                tv_good.setText(good);//赞
                tv_bad.setText(bad);//踩

                TextView no_comment = (TextView) findViewById(R.id.no_comment);
                //如果没有评论则显示暂无评论，否则隐藏暂无评论
                if (commentNum.equals("0")) {
                    no_comment.setVisibility(View.VISIBLE);
                } else {
                    no_comment.setVisibility(View.GONE);
                }
                //把图片分割成数组
                final String[] array_img = images.split(",");
                grid_item = (StationaryGridview) findViewById(R.id.gv);
                ImageView iv_img = (ImageView) findViewById(R.id.iv_img);
                LinearLayout line_iv_img = (LinearLayout) findViewById(R.id.line_iv_img);
                ImageView iv_img1 = (ImageView) findViewById(R.id.iv_img1);
                ImageView iv_img2 = (ImageView) findViewById(R.id.iv_img2);
                //如果只有一张图片则iv_img组件显示，其他隐藏
                if (array_img.length == 1) {
                    iv_img.setVisibility(View.VISIBLE);
                    grid_item.setVisibility(View.GONE);
                    line_iv_img.setVisibility(View.GONE);
                    ImageOptions options3 = new ImageOptions.Builder()
                            .setLoadingDrawableId(R.mipmap.loading_img)//加载过程中的等待图片
                            .setFailureDrawableId(R.mipmap.failure_img)//加载出错显示的图片
                            .build();
                            x.image().bind(iv_img, "http://tr.zzapi.gson.cn/" + images, options3);
                            //查看大图
                            iv_img.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(BrokeDetailsA.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", 0);
                                    startActivity(intent);
                                }
                            });
                        } else if (array_img.length == 2) {//如果只有两张图片则line_iv_img组件显示，其他隐藏
                            iv_img.setVisibility(View.GONE);
                            grid_item.setVisibility(View.GONE);
                            line_iv_img.setVisibility(View.VISIBLE);
                            ImageOptions options3 = new ImageOptions.Builder()
                                    .setLoadingDrawableId(R.mipmap.loading_img)//加载过程中的等待图片
                                    .setFailureDrawableId(R.mipmap.failure_img)//加载出错显示的图片
                                    .build();
                            x.image().bind(iv_img1, "http://tr.zzapi.gson.cn/" + array_img[0], options3);
                            x.image().bind(iv_img2, "http://tr.zzapi.gson.cn/" + array_img[1], options3);
                            //查看大图
                            iv_img1.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(BrokeDetailsA.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", 0);
                                    startActivity(intent);
                                }
                            });
                            //查看大图
                            iv_img2.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(BrokeDetailsA.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", 1);
                                    startActivity(intent);
                                }
                            });
                        } else {
                            iv_img.setVisibility(View.GONE);
                            line_iv_img.setVisibility(View.GONE);
                            grid_item.setVisibility(View.VISIBLE);
                            //图片适配器
                            class ImgAdapter extends BaseAdapter {
                                public ImgAdapter() {
                                    list = new ArrayList<>();
                                    for (int i = 0; i < array_img.length; i++) {
                                        Map<String, Object> map = new HashMap<>();
                                        map.put("img", array_img[i]);
                                        list.add(map);
                                    }
                                }

                                public int getCount() {
                                    return list.size();
                                }

                                public Object getItem(int position) {
                                    return list.get(position);
                                }

                                public long getItemId(int position) {
                                    return 0;
                                }

                                public View getView(int position, View convertView, ViewGroup parent) {
                                    final ViewHolder viewHolder;
                                    if (convertView == null) {
                                        convertView = LayoutInflater.from(BrokeDetailsA.this).inflate(R.layout.broke_img, null);
                                        viewHolder = new ViewHolder();
                                        viewHolder.Iv_img = (ImageView) convertView.findViewById(R.id.broke_img);
                                        convertView.setTag(viewHolder);
                                    } else {
                                        viewHolder = (ViewHolder) convertView.getTag();
                                    }
                                    ImageOptions options3 = new ImageOptions.Builder()
                                            .setLoadingDrawableId(R.mipmap.loading_img)//加载过程中的等待图片
                                            .setFailureDrawableId(R.mipmap.failure_img)//加载出错显示的图片
                                            .build();
                                    x.image().bind(viewHolder.Iv_img, "http://tr.zzapi.gson.cn/" + list.get(position).get("img"), options3);
                                    return convertView;
                                }

                                class ViewHolder {
                                    public ImageView Iv_img;
                                }
                            }
                            //添加适配器
                            grid_item.setAdapter(new ImgAdapter());
                            //查看大图
                            grid_item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                    Intent intent = new Intent(BrokeDetailsA.this, BigPicture.class);
                                    intent.putExtra("img", images + "");
                                    intent.putExtra("imgPosition", position);
                                    startActivity(intent);
                                }
                            });
                        }
                        //设置按钮的监听器
                        ImageView bt = (ImageView) findViewById(R.id.cs);
                        final String finalImages1 = images;
                        bt.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(BrokeDetailsA.this);
                                builder.setTitle("选择");
                                final BaseAdapter adapter = new tabAdapter();
                                //单击事件
                                builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        Map<String, Object> map = (Map<String, Object>) adapter.getItem(which);
                                        //加载图片
                                        if (which == 0) {
                                            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(BrokeDetailsA.this);
                                            SharedPreferences.Editor editor = sp.edit();
                                            editor.putString("LoadImage", "yes1");
                                            editor.commit();
                                        }
                                        //不加载图片
                                        if (which == 1) {
                                            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(BrokeDetailsA.this);
                                            SharedPreferences.Editor editor = sp.edit();
                                            editor.putString("LoadImage", "no1");
                                            editor.commit();
                                        }
                                        if (which == 2) {
                                            LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                                            linear_img.setVisibility(View.GONE);
                                        }
                                        if (which == 3 & finalImages1.length() != 0) {
                                            LinearLayout linear_img = (LinearLayout) findViewById(R.id.line_img);
                                            linear_img.setVisibility(View.VISIBLE);
                                        }
                                    }
                                });
                                AlertDialog dialog = builder.create();
                                dialog.show();
                                //设置高度宽度和大小
                                WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                                params.width = 500;
                                params.height = 800;
                                params.x = width - 400;
                                params.y = -(height / 2 - 580);
                                dialog.getWindow().setAttributes(params);
                                //设置动画
                                Window window = dialog.getWindow();
                                window.setWindowAnimations(R.style.dialog_anim);
                            }
                        });
            }

            @Override
            public void onError(Throwable throwable, boolean b) {

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //评论区的方法
    public void comment(final String child_Id) {
        //获取评论列表
        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/comment/list?newsId=" + child_Id + "&page=1&rows=20");
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String s) {
                JSONObject c_json = JSON.parseObject(s);
                final JSONArray c_data = c_json.getJSONArray("data");
                for (int i = 0; i < c_data.size(); i++) {
                    final JSONObject c_obj1 = c_data.getJSONObject(i);
                    final String c_content = c_obj1.getString("content");//评论内容
                    final String c_dateline = c_obj1.getString("dateline");//评论时间
                    final String c_id = c_obj1.getString("id");//评论id
                    final String c_user = c_obj1.getString("user");//用户

                    LinearLayout linear_comment = (LinearLayout) findViewById(R.id.linear_comment);//评论总布局
                    //设置参与区
                    if (i != 0) {
                        //分割线
                        TextView text = new TextView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp11 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.MATCH_PARENT,
                                2
                        );
                        lp11.setMargins(10, 10, 10, 10);
                        text.setLayoutParams(lp11);
                        text.setBackgroundColor(0xffaaaaaa);
                        linear_comment.addView(text);
                    }
                    //用户信息
                    LinearLayout u_linear1 = new LinearLayout(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MATCH_PARENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT
                    );
                    lp1.setMargins(10, 10, 10, 10);
                    u_linear1.setLayoutParams(lp1);
                    u_linear1.setOrientation(LinearLayout.HORIZONTAL);
                    linear_comment.addView(u_linear1);

                    //参与用户头像
                    ImageView u_iv_avatar = new ImageView(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(130, 130);
                    lp2.gravity = Gravity.CENTER_VERTICAL;
                    u_iv_avatar.setLayoutParams(lp2);
                    u_linear1.addView(u_iv_avatar);
                    //昵称、性别、第几楼、时间
                    LinearLayout u_linear2 = new LinearLayout(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(
                            0,
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            1
                    );
                    lp3.setMargins(20, 10, 10, 10);
                    lp3.gravity = Gravity.CENTER_VERTICAL;
                    u_linear2.setLayoutParams(lp3);
                    u_linear2.setOrientation(LinearLayout.VERTICAL);
                    u_linear1.addView(u_linear2);
                    //昵称、性别
                    LinearLayout u_linear3 = new LinearLayout(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp4 = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT
                    );
                    lp4.gravity = Gravity.CENTER_VERTICAL;
                    u_linear3.setLayoutParams(lp4);
                    u_linear3.setOrientation(LinearLayout.HORIZONTAL);
                    u_linear2.addView(u_linear3);
                    //用户昵称
                    //android:singleLine="true"超过一行末尾会显示...
                    final TextView u_tv_nickname = new TextView(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp5 = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            1
                    );
                    u_tv_nickname.setSingleLine(true);
                    u_tv_nickname.setLayoutParams(lp5);
                    u_linear3.addView(u_tv_nickname);
                    //性别
                    ImageView u_iv_gender = new ImageView(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp6 = new LinearLayout.LayoutParams(50, 50);
                    lp4.setMargins(10, 10, 10, 10);
                    lp6.gravity = Gravity.CENTER_VERTICAL;
                    u_iv_gender.setLayoutParams(lp6);
                    u_linear3.addView(u_iv_gender);
                    //第几楼、时间
                    LinearLayout u_linear4 = new LinearLayout(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp7 = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT
                    );
                    lp7.gravity = Gravity.CENTER_VERTICAL;
                    u_linear4.setLayoutParams(lp7);
                    u_linear4.setOrientation(LinearLayout.HORIZONTAL);
                    u_linear2.addView(u_linear4);
                    //第几楼
                    final TextView floor = new TextView(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp8 = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT
                    );
                    floor.setText((c_data.size() - i) + "楼");
                    floor.setTextColor(0xffaaaaaa);
                    floor.setTextSize(12);
                    lp8.setMargins(0, 0, 20, 0);
                    floor.setLayoutParams(lp8);
                    u_linear4.addView(floor);
                    //时间
                    TextView u_lastUpdate = new TextView(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp9 = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT
                    );
                    u_lastUpdate.setText(c_dateline);
                    u_lastUpdate.setLayoutParams(lp9);
                    u_linear4.addView(u_lastUpdate);
                    u_lastUpdate.setTextColor(0xffaaaaaa);
                    u_lastUpdate.setTextSize(12);
                    //回复
                    ImageView reply1 = new ImageView(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp_reply1 = new LinearLayout.LayoutParams(60, 50);
                    lp_reply1.setMargins(30, 5, 5, 5);
                    lp_reply1.gravity = Gravity.CENTER_VERTICAL;
                    reply1.setImageResource(R.mipmap.ysw_reply);
                    reply1.setLayoutParams(lp_reply1);
                    u_linear4.addView(reply1);
                    //回复的单击事件
                    reply1.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //调用评论弹窗方法
                            reolyComment(c_id, c_content, floor, u_tv_nickname);
                        }
                    });
                    //显示子评论箭头
                    final ToggleButton display1 = new ToggleButton(BrokeDetailsA.this);
                    display1.setTextOn(" ");
                    display1.setTextOff(" ");
                    LinearLayout.LayoutParams lp_display = new LinearLayout.LayoutParams(70, 70);
                    lp_display.setMargins(20, 5, 50, 5);
                    lp_display.gravity = Gravity.CENTER_VERTICAL;
                    display1.setLayoutParams(lp_display);
                    display1.setBackgroundResource(R.drawable.ysw_display_toggle);
                    display1.setVisibility(View.GONE);
                    u_linear1.addView(display1);
                    //内容
                    TextView u_tv_content = new TextView(BrokeDetailsA.this);
                    LinearLayout.LayoutParams lp10 = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT
                    );
                    u_tv_content.setText(c_content);
                    u_tv_content.setTextColor(0xff000000);
                    lp10.setMargins(30, 5, 5, 15);
                    u_tv_content.setLayoutParams(lp10);
                    linear_comment.addView(u_tv_content);
                    u_tv_nickname.setText("游客");
                    //子评论线性布局
                    final LinearLayout comment_linear2 = new LinearLayout(BrokeDetailsA.this);
                    LinearLayout.LayoutParams comment_lp = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MATCH_PARENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT
                    );
//                    comment_lp.setMargins(30, 10, 10, 10);
                    comment_linear2.setLayoutParams(comment_lp);
                    comment_linear2.setBackgroundColor(0x33FF9933);
                    comment_linear2.setOrientation(LinearLayout.VERTICAL);
                    comment_linear2.setVisibility(View.GONE);
                    linear_comment.addView(comment_linear2);
                    //设置箭头的监听器
                    display1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            if (isChecked) {
                                comment_linear2.setVisibility(View.VISIBLE);
                            } else {
                                comment_linear2.setVisibility(View.GONE);
                            }
                        }
                    });

                    //设置头像
                    ImageOptions options3 = new ImageOptions.Builder()
                            .setCircular(true)//设置圆形
                            .setLoadingDrawableId(R.mipmap.default_avatar)//加载过程中的等待图片
                            .setFailureDrawableId(R.mipmap.default_avatar)//加载出错显示的图片
                            .build();
                    x.image().bind(u_iv_avatar, "", options3);

                    //如果用户不为null，则赋用户的值
                    if (c_obj1.getString("user") != null) {
                        JSONObject c_obj2 = JSON.parseObject(c_user);
                        String c_avatar = c_obj2.getString("avatar");//头像
                        String c_nickName = c_obj2.getString("nickName");//昵称
                        String c_user_id = c_obj2.getString("id");//用户id
                        String c_gender = c_obj2.getString("gender");//用户性别
                        //设置头像
                        ImageOptions options4 = new ImageOptions.Builder()
                                .setCircular(true)//设置圆形
                                .setLoadingDrawableId(R.mipmap.default_avatar)//加载过程中的等待图片
                                .setFailureDrawableId(R.mipmap.default_avatar)//加载出错显示的图片
                                .build();
                        x.image().bind(u_iv_avatar, "http://tr.zzapi.gson.cn/" + c_avatar, options4);
                        u_tv_nickname.setText(c_nickName);//设置昵称
                        //设置性别
                        if (c_gender.equals("BOY")) {
                            u_iv_gender.setImageResource(R.mipmap.boy);
                        } else {
                            u_iv_gender.setImageResource(R.mipmap.girl);
                        }
                    }
                    //调用子评论的方法
                    comment333(c_id, display1, comment_linear2);
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //赞方法
    public void good(final String goodId) {
        LinearLayout goodView = (LinearLayout) findViewById(R.id.good_linear);
        goodView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点赞
                RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/news/goodOrBad?id=" + goodId + "&type=GOOD");
                x.http().get(params, new Callback.CommonCallback<String>() {

                    @Override
                    public void onSuccess(String s) {
                        JSONObject good_json = JSON.parseObject(s);
                        final String sss = good_json.getString("message");
                        Toast.makeText(BrokeDetailsA.this, sss, Toast.LENGTH_LONG).show();
                        //获取爆料列表设置赞的数量
                        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/news/list?type=FACT&page=1&rows=50");
                        x.http().get(params, new Callback.CommonCallback<String>() {
                            @Override
                            public void onSuccess(String s) {
                                com.alibaba.fastjson.JSONObject json = JSON.parseObject(s);
                                JSONArray good_data = json.getJSONArray("data");
                                for (int i = 0; i < good_data.size(); i++) {
                                    JSONObject good_obj = good_data.getJSONObject(i);
                                    String id1 = good_obj.getString("id");
                                    if (goodId.equals(id1)) {
                                        String good1 = good_obj.getString("good");//赞
                                        tv_good.setText(good1);//设置赞
                                        if (sss.equals("赞成功")) {
                                            ImageView good_img = (ImageView) findViewById(R.id.good_img);
                                            good_img.setImageResource(R.mipmap.ysw_good2);
                                        } else {
                                            ImageView good_img = (ImageView) findViewById(R.id.good_img);
                                            good_img.setImageResource(R.mipmap.ysw_good1);
                                        }
                                        break;
                                    }
                                }
                            }

                            @Override
                            public void onError(Throwable throwable, boolean b) {
                            }

                            @Override
                            public void onCancelled(CancelledException e) {
                            }

                            @Override
                            public void onFinished() {
                            }
                        });
                    }

                    @Override
                    public void onError(Throwable throwable, boolean b) {

                    }

                    @Override
                    public void onCancelled(CancelledException e) {

                    }

                    @Override
                    public void onFinished() {

                    }
                });
            }
        });
    }

    public void bad(final String badId) {
        LinearLayout badView = (LinearLayout) findViewById(R.id.bad_linear);
        badView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //踩
                RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/news/goodOrBad?id=" + badId + "&type=BAD");
                x.http().get(params, new Callback.CommonCallback<String>() {

                    @Override
                    public void onSuccess(String s) {
                        JSONObject bad_json = JSON.parseObject(s);
                        final String sss = bad_json.getString("message");
                        Toast.makeText(BrokeDetailsA.this, sss, Toast.LENGTH_LONG).show();
                        //获取爆料列表设置踩的数量
                        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/news/list?type=FACT&page=1&rows=50");
                        x.http().get(params, new Callback.CommonCallback<String>() {
                            @Override
                            public void onSuccess(String s) {
                                com.alibaba.fastjson.JSONObject json = JSON.parseObject(s);
                                JSONArray bad_data = json.getJSONArray("data");
                                for (int i = 0; i < bad_data.size(); i++) {
                                    JSONObject bad_obj = bad_data.getJSONObject(i);
                                    String id1 = bad_obj.getString("id");
                                    if (badId.equals(id1)) {
                                        String bad1 = bad_obj.getString("bad");//踩
                                        tv_bad.setText(bad1);//设置踩
                                        if (sss.equals("踩成功")) {
                                            ImageView bad_img = (ImageView) findViewById(R.id.bad_img);
                                            bad_img.setImageResource(R.mipmap.ysw_bad2);
                                        } else {
                                            ImageView bad_img = (ImageView) findViewById(R.id.bad_img);
                                            bad_img.setImageResource(R.mipmap.ysw_bad1);
                                        }
                                        break;
                                    }
                                }
                            }

                            @Override
                            public void onError(Throwable throwable, boolean b) {
                            }

                            @Override
                            public void onCancelled(CancelledException e) {
                            }

                            @Override
                            public void onFinished() {
                            }
                        });
                    }

                    @Override
                    public void onError(Throwable throwable, boolean b) {

                    }

                    @Override
                    public void onCancelled(CancelledException e) {

                    }

                    @Override
                    public void onFinished() {

                    }
                });
            }
        });
    }

    //子评论的方法
    public void comment333(final String c_id, final ToggleButton display1, final LinearLayout comment_linear2) {
        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/comment/list?newsId=" + c_id + "&page=1&rows=20");
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String s) {
                JSONObject c_json2 = JSON.parseObject(s);
                JSONArray c_data2 = c_json2.getJSONArray("data");
                if (c_json2.getJSONArray("data") != null) {
                    for (int j = 0; j < c_data2.size(); j++) {
                        JSONObject c_obj2 = c_data2.getJSONObject(j);
                        final String c_id2 = c_obj2.getString("id");//评论id
                        final String c_content2 = c_obj2.getString("content");//评论内容
                        String c_dateline2 = c_obj2.getString("dateline");//评论时间
                        String c_user2 = c_obj2.getString("user");//用户

                        //设置参与区
                        if (j != 0) {
                            //分割线
                            TextView text = new TextView(BrokeDetailsA.this);
                            LinearLayout.LayoutParams lp11 = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT,
                                    2
                            );
                            lp11.setMargins(10, 10, 10, 10);
                            text.setLayoutParams(lp11);
                            text.setBackgroundColor(0xff0099FF);
                            comment_linear2.addView(text);
                        } else {
                            display1.setVisibility(View.VISIBLE);//显示箭头
                        }
                        //用户信息
                        LinearLayout u_linear1 = new LinearLayout(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.MATCH_PARENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT
                        );
                        lp1.setMargins(10, 10, 10, 10);
                        u_linear1.setLayoutParams(lp1);
                        u_linear1.setOrientation(LinearLayout.HORIZONTAL);
                        comment_linear2.addView(u_linear1);

                        //参与用户头像
                        ImageView u_iv_avatar = new ImageView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(130, 130);
                        lp2.gravity = Gravity.CENTER_VERTICAL;
                        u_iv_avatar.setLayoutParams(lp2);
                        u_linear1.addView(u_iv_avatar);
                        //昵称、性别、第几楼、时间
                        LinearLayout u_linear2 = new LinearLayout(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(
                                0,
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                1
                        );
                        lp3.setMargins(20, 10, 10, 10);
                        lp3.gravity = Gravity.CENTER_VERTICAL;
                        u_linear2.setLayoutParams(lp3);
                        u_linear2.setOrientation(LinearLayout.VERTICAL);
                        u_linear1.addView(u_linear2);
                        //昵称、性别
                        LinearLayout u_linear3 = new LinearLayout(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp4 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT
                        );
                        lp4.gravity = Gravity.CENTER_VERTICAL;
                        u_linear3.setLayoutParams(lp4);
                        u_linear3.setOrientation(LinearLayout.HORIZONTAL);
                        u_linear2.addView(u_linear3);
                        //用户昵称
                        //android:singleLine="true"超过一行末尾会显示...
                        final TextView u_tv_nickname = new TextView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp5 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                1
                        );
                        u_tv_nickname.setSingleLine(true);
                        u_tv_nickname.setLayoutParams(lp5);
                        u_linear3.addView(u_tv_nickname);
                        //性别
                        ImageView u_iv_gender = new ImageView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp6 = new LinearLayout.LayoutParams(50, 50);
                        lp4.setMargins(10, 10, 10, 10);
                        lp6.gravity = Gravity.CENTER_VERTICAL;
                        u_iv_gender.setLayoutParams(lp6);
                        u_linear3.addView(u_iv_gender);
                        //第几楼、时间
                        LinearLayout u_linear4 = new LinearLayout(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp7 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT
                        );
                        lp7.gravity = Gravity.CENTER_VERTICAL;
                        u_linear4.setLayoutParams(lp7);
                        u_linear4.setOrientation(LinearLayout.HORIZONTAL);
                        u_linear2.addView(u_linear4);
                        //第几楼
                        final TextView floor = new TextView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp8 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT
                        );
                        floor.setText((c_data2.size() - j) + "楼");
                        floor.setTextColor(0xffaaaaaa);
                        floor.setTextSize(12);
                        lp8.setMargins(0, 0, 20, 0);
                        floor.setLayoutParams(lp8);
                        u_linear4.addView(floor);
                        //时间
                        TextView u_lastUpdate = new TextView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp9 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT
                        );
                        u_lastUpdate.setText(c_dateline2);
                        u_lastUpdate.setLayoutParams(lp9);
                        u_linear4.addView(u_lastUpdate);
                        u_lastUpdate.setTextColor(0xffaaaaaa);
                        u_lastUpdate.setTextSize(12);
                        //回复
                        ImageView reply1 = new ImageView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp_reply1 = new LinearLayout.LayoutParams(60, 50);
                        lp_reply1.gravity = Gravity.CENTER_VERTICAL;
                        lp_reply1.setMargins(30, 5, 5, 5);

                        reply1.setImageResource(R.mipmap.ysw_reply);
                        reply1.setLayoutParams(lp_reply1);
                        u_linear4.addView(reply1);
                        //回复的单击事件
                        reply1.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                //调用评论弹窗方法
                                reolyComment(c_id2, c_content2, floor, u_tv_nickname);
                            }
                        });
                        //显示子评论箭头
                        final ToggleButton display2 = new ToggleButton(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp_display = new LinearLayout.LayoutParams(70, 70);
                        lp_display.setMargins(10, 5, 50, 5);
                        lp_display.gravity = Gravity.CENTER_VERTICAL;
                        display2.setLayoutParams(lp_display);
                        display2.setTextOn("");
                        display2.setTextOff("");
                        display2.setBackgroundResource(R.drawable.ysw_display_toggle);
                        display2.setVisibility(View.GONE);
                        u_linear1.addView(display2);
                        //内容
                        TextView u_tv_content = new TextView(BrokeDetailsA.this);
                        LinearLayout.LayoutParams lp10 = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.WRAP_CONTENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT
                        );
                        u_tv_content.setText(c_content2);
                        u_tv_content.setTextColor(0xff000000);
                        lp10.setMargins(30, 5, 5, 15);
                        u_tv_content.setLayoutParams(lp10);
                        comment_linear2.addView(u_tv_content);
                        u_tv_nickname.setText("游客");
                        //设置头像
                        ImageOptions options3 = new ImageOptions.Builder()
                                .setCircular(true)//设置圆形
                                .setLoadingDrawableId(R.mipmap.default_avatar)//加载过程中的等待图片
                                .setFailureDrawableId(R.mipmap.default_avatar)//加载出错显示的图片
                                .build();
                        x.image().bind(u_iv_avatar, "", options3);

                        //如果用户不为null，则赋用户的值
                        if (c_obj2.getString("user") != null) {
                            JSONObject c_obj3 = JSON.parseObject(c_user2);
                            String c_avatar = c_obj3.getString("avatar");//头像
                            String c_nickName = c_obj3.getString("nickName");//昵称
                            String c_user_id = c_obj3.getString("id");//用户id
                            String c_gender = c_obj3.getString("gender");//用户性别

                            //设置头像
                            ImageOptions options4 = new ImageOptions.Builder()
                                    .setCircular(true)//设置圆形
                                    .setLoadingDrawableId(R.mipmap.default_avatar)//加载过程中的等待图片
                                    .setFailureDrawableId(R.mipmap.default_avatar)//加载出错显示的图片
                                    .build();
                            x.image().bind(u_iv_avatar, "http://tr.zzapi.gson.cn/" + c_avatar, options4);
                            u_tv_nickname.setText(c_nickName);//设置昵称
                            //设置性别
                            if (c_gender.equals("BOY")) {
                                u_iv_gender.setImageResource(R.mipmap.boy);
                            } else {
                                u_iv_gender.setImageResource(R.mipmap.girl);
                            }
                        }
                        //子子评论线性布局
                        final LinearLayout comment_linear3 = new LinearLayout(BrokeDetailsA.this);
                        LinearLayout.LayoutParams comment_lp = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.MATCH_PARENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT
                        );
//                        comment_lp.setMargins(30, 10, 10, 10);
                        comment_linear3.setLayoutParams(comment_lp);
                        comment_linear3.setBackgroundColor(0x33FF9933);
                        comment_linear3.setOrientation(LinearLayout.VERTICAL);
                        comment_linear3.setVisibility(View.GONE);
                        comment_linear2.addView(comment_linear3);
                        //箭头的监听事件
                        display2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                                if (isChecked) {
                                    comment_linear3.setVisibility(View.VISIBLE);
                                } else {
                                    comment_linear3.setVisibility(View.GONE);
                                }
                            }
                        });
                        //子子评论
                        comment333(c_id2, display2, comment_linear3);
                    }
                }
            }

            @Override
            public void onError(Throwable throwable, boolean b) {

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //评论弹窗方法
    public void reolyComment(final String c_id, String c_content, TextView floor, TextView u_tv_nickname) {
        /*Toast.makeText(BrokeDetailsA.this, "评论id:" + c_id + "内容:" + c_content, Toast.LENGTH_LONG).show();
        //获取布局
        View view = LayoutInflater.from(BrokeDetailsA.this).inflate(R.layout.broke_comment, null);
        final EditText edit_comment = (EditText) view.findViewById(R.id.edit_comment);
        edit_comment.setHint("请输入评论内容");
        //创建Dialog
        final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(BrokeDetailsA.this);
        dialogBuilder
                .withTitle("评论")  //标题
                .withMessage("评论" + floor.getText() + " " + u_tv_nickname.getText())
                .withMessageColor("#ff000000")
                .withTitleColor("#ffffffff") //标题颜色
                .withDividerColor("#1133CC99") //按钮透明度
                .withDialogColor("#ff66CCFF") //Dialog整体颜色
                .isCancelableOnTouchOutside(false)  //点击Dialog以外是否取消
                .withDuration(500)//动画延迟时间
                .withEffect(Effectstype.SlideBottom) //动画类型
                .setCustomView(view, BrokeDetailsA.this) //加载内容布局
                .withButton1Text("评论") //按钮1
                .withButton2Text("取消") //按钮2
                .setButton1Click(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/comment/comment");
                        params.addBodyParameter("newsId", c_id);
                        params.addBodyParameter("content", edit_comment.getText().toString());
                        x.http().post(params, new Callback.CommonCallback<String>() {
                            @Override
                            public void onSuccess(String s) {
                                JSONObject json = JSON.parseObject(s);
//                                String success = (String) json.get("success");
                                if (json.get("success").equals(true)) {
                                    Toast.makeText(BrokeDetailsA.this, "评论成功！", Toast.LENGTH_LONG).show();
                                    dialogBuilder.dismiss();
                                } else {
                                    Toast.makeText(BrokeDetailsA.this, "评论失败！", Toast.LENGTH_LONG).show();
                                }
                            }

                            @Override
                            public void onError(Throwable throwable, boolean b) {

                            }

                            @Override
                            public void onCancelled(CancelledException e) {

                            }

                            @Override
                            public void onFinished() {

                            }
                        });
                    }
                })
                .setButton2Click(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialogBuilder.dismiss();
                    }
                })
                .show();*/
        View view = LayoutInflater.from(BrokeDetailsA.this).inflate(R.layout.broke_comment, null);
        TextView message = (TextView) view.findViewById(R.id.message);
        final EditText edit_comment = (EditText) view.findViewById(R.id.edit_comment);
        TextView bt1 = (TextView) view.findViewById(R.id.bt1);
        TextView bt2 = (TextView) view.findViewById(R.id.bt2);
        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(BrokeDetailsA.this);
        builder.setView(view);
        final android.app.AlertDialog dialog = builder.create();
        dialog.show();
        // 设置宽高
        dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        message.setText("评论" + floor.getText() + " " + u_tv_nickname.getText());
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/comment/comment");
                params.addBodyParameter("newsId", c_id);
                params.addBodyParameter("content", edit_comment.getText().toString());
                x.http().post(params, new Callback.CommonCallback<String>() {
                    @Override
                    public void onSuccess(String s) {
                        JSONObject json = JSON.parseObject(s);
                        if (json.get("success").equals(true)) {
                            Toast.makeText(BrokeDetailsA.this, "评论成功！", Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        } else {
                            Toast.makeText(BrokeDetailsA.this, "评论失败！", Toast.LENGTH_LONG).show();
                        }
                    }

                    @Override
                    public void onError(Throwable throwable, boolean b) {

                    }

                    @Override
                    public void onCancelled(CancelledException e) {

                    }

                    @Override
                    public void onFinished() {

                    }
                });
            }
        });
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    //评论的方法
    public void publishComment(final String passId) {
        final EditText comment = (EditText) findViewById(R.id.comment);
        Button publish = (Button) findViewById(R.id.publish);
        publish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (comment.getText().toString().equals("")) {
                    Toast.makeText(BrokeDetailsA.this, "请输入评论！", Toast.LENGTH_LONG).show();
                } else {
                    RequestParams params = new RequestParams("http://tr.zzapi.gson.cn/api/comment/comment");
                    params.addBodyParameter("newsId", passId);
                    params.addBodyParameter("content", comment.getText().toString());
                    x.http().post(params, new Callback.CommonCallback<String>() {

                        @Override
                        public void onSuccess(String s) {
                            JSONObject json = JSON.parseObject(s);
                            if (json.get("success").equals(true)) {
                                Toast.makeText(BrokeDetailsA.this, "评论成功！", Toast.LENGTH_LONG).show();
                                comment.setText("");
                            } else {
                                Toast.makeText(BrokeDetailsA.this, "评论失败！", Toast.LENGTH_LONG).show();
                            }
                        }

                        @Override
                        public void onError(Throwable throwable, boolean b) {

                        }

                        @Override
                        public void onCancelled(CancelledException e) {

                        }

                        @Override
                        public void onFinished() {

                        }
                    });
                }
            }
        });
    }

    //选项卡对应的Adaper
    class tabAdapter extends BaseAdapter {
        public int getCount() {
            return list_tab.size();
        }

        public Object getItem(int position) {
            return list_tab.get(position);
        }

        public long getItemId(int position) {
            return 0;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            final ViewHolder viewHolder;
            if (convertView == null) {
                convertView = LayoutInflater.from(BrokeDetailsA.this).inflate(R.layout.tab, null);
                viewHolder = new ViewHolder();
                viewHolder.tv = (TextView) convertView.findViewById(R.id.tv);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.tv.setText((String) list_tab.get(position).get("tabs"));
            return convertView;
        }

        class ViewHolder {
            public TextView tv;
        }
    }
}
